//
//  HPmainViewController.swift
//  HPweibo007
//
//  Created by  何平 on 15/12/16.
//  Copyright © 2015年 Alan. All rights reserved.
//

import UIKit

class HPmainViewController: UITabBarController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar=HPmainTabBar()
        setValue(mainTabbar, forKey: "tabBar")
        
        let homeVC=HPHomeViewController()
        addChildVC(homeVC, title: "首页", imageName: "tabbar_home")
        
         let messageVC=HPMessageViewController()
        addChildVC(messageVC, title: "消息", imageName: "tabbar_message_center")
        
       
        let discoveryVC=HPDiscoveryViewController()
        addChildVC(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC=HPProfileViewController()
        
        addChildVC(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildVC(childController: UIViewController, title:String, imageName:String) {
    
        self.addChildViewController(UINavigationController(rootViewController: childController))
        
        childController.title=title
        
        childController.tabBarItem.image=UIImage(named: imageName)
        
        let highLightedName = imageName+"_highlighted"
        
        childController.tabBarItem.selectedImage=UIImage(named: highLightedName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
    }
}